package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.utils.Base64Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.ShAppointment;
import com.ruoyi.system.service.IShAppointmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 店铺预约信息Controller
 * 
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/appointment")
public class ShAppointmentController extends BaseController
{
    @Autowired
    private IShAppointmentService shAppointmentService;

    /**
     * 查询店铺预约信息列表
     */
    @RequiresPermissions("system:appointment:list")
    @GetMapping("/list")
    public TableDataInfo list(ShAppointment shAppointment)
    {
        SysUser user = SecurityUtils.getLoginUser().getSysUser();
        if (!SysUser.isAdmin(user.getUserId())) {
            if (Base64Util.hasYwType(user.getYwType(), "1")) {
                shAppointment.setAppId(user.getAppIdm());
            }else if (Base64Util.hasYwType(user.getYwType(), "2")) {
                shAppointment.setAppId(user.getAppIdf());
            }else if (Base64Util.hasYwType(user.getYwType(), "3")) {
                shAppointment.setAppId(user.getAppId());
            }
        }
        startPage();
        List<ShAppointment> list = shAppointmentService.selectShAppointmentList(shAppointment);
        return getDataTable(list);
    }

    /**
     * 导出店铺预约信息列表
     */
    @RequiresPermissions("system:appointment:export")
    @Log(title = "店铺预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShAppointment shAppointment)
    {
        SysUser user = SecurityUtils.getLoginUser().getSysUser();
        if (!SysUser.isAdmin(user.getUserId())) {
            if (Base64Util.hasYwType(user.getYwType(), "1")) {
                shAppointment.setAppId(user.getAppIdm());
            }else if (Base64Util.hasYwType(user.getYwType(), "2")) {
                shAppointment.setAppId(user.getAppIdf());
            }else if (Base64Util.hasYwType(user.getYwType(), "3")) {
                shAppointment.setAppId(user.getAppId());
            }
        }
        List<ShAppointment> list = shAppointmentService.selectShAppointmentList(shAppointment);
        ExcelUtil<ShAppointment> util = new ExcelUtil<ShAppointment>(ShAppointment.class);
        util.exportExcel(response, list, "店铺预约信息数据");
    }

    /**
     * 获取店铺预约信息详细信息
     */
    @RequiresPermissions("system:appointment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shAppointmentService.selectShAppointmentById(id));
    }

    /**
     * 新增店铺预约信息
     */
    @RequiresPermissions("system:appointment:add")
    @Log(title = "店铺预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShAppointment shAppointment)
    {
        return toAjax(shAppointmentService.insertShAppointment(shAppointment));
    }

    /**
     * 修改店铺预约信息
     */
    @RequiresPermissions("system:appointment:edit")
    @Log(title = "店铺预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShAppointment shAppointment)
    {
        return toAjax(shAppointmentService.updateShAppointment(shAppointment));
    }

    /**
     * 删除店铺预约信息
     */
    @RequiresPermissions("system:appointment:remove")
    @Log(title = "店铺预约信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shAppointmentService.deleteShAppointmentByIds(ids));
    }
}
